import akka.actor.{Actor, ActorRef}

class Slaver(master: ActorRef, name: String) extends Actor{
  val random = scala.util.Random

  override def receive: Receive = {
    case Register =>
      master ! Register(name)
    case Ack =>
      val seconds = random.nextInt(10)
      println(s"$name received ack, waiting for $seconds seconds...")
      // 发送心跳成功之后，随机休眠几秒钟，模拟网络延迟等意外
      Thread.sleep(seconds * 1000)
      master ! Beat(name)
  }
}
